//
//  YYJLAllconmentCell.m
//  YuanyangJinlou
//
//  Created by mac004 on 2017/1/6.
//  Copyright © 2017年 suli19910309@qq.com. All rights reserved.
//

#import "YYJLAllconmentCell.h"
@interface YYJLAllconmentCell()
{
    UIImageView * headerView;//头像
    UIImageView * level;//等级
    UILabel     * nameLb;//姓名
    UILabel     * postionLb;//职位
    UILabel     * timeLb;//时间
    UILabel     * contentLb;//内容
    
    UIImageView *  _lineImg;
}
@end
@implementation YYJLAllconmentCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self =[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatUI];
    }
    return self;
}
-(void)creatUI{
    headerView=[[UIImageView alloc]initWithFrame:CGRectMake(12*PER_WIDTH, 15*PER_HEIGHT, 40*PER_WIDTH, 40*PER_WIDTH)];
    headerView.layer.cornerRadius=headerView.height/2;
    headerView.layer.masksToBounds=YES;
    headerView.image=[UIImage imageNamed:@"touxiang2-80x80"];
    [self.contentView addSubview:headerView];
    
    timeLb=[MyControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-12*PER_WIDTH-100*PER_WIDTH, 25*PER_HEIGHT, 100*PER_WIDTH, 12*PER_HEIGHT) Font:12 Text:@"12-04 19:00" Color:FEELT_COLOR];
    timeLb.textAlignment=NSTextAlignmentRight;
    timeLb.font=[UIFont fontWithName :HLT size:12*PER_HEIGHT];
    [self.contentView addSubview:timeLb];
    
    
    nameLb=[MyControl createLabelWithFrame:CGRectMake(headerView.right+10*PER_WIDTH, 20*PER_HEIGHT, 120, 14*PER_HEIGHT) Font:14 Text:@"张洋" Color:BLACK_COLOR];
    [self.contentView addSubview:nameLb];
    
    UIImage * levelImg =[UIImage imageNamed:@"5"];
    
    level=[[UIImageView alloc]initWithFrame:CGRectMake(nameLb.left, nameLb.bottom+10*PER_HEIGHT, levelImg.size.width*PER_WIDTH, levelImg.size.height*PER_HEIGHT)];
    level.image=levelImg;
    [self.contentView addSubview:level];
    
    postionLb=[MyControl createLabelWithFrame:CGRectMake(level.right+10*PER_WIDTH, nameLb.bottom+10*PER_HEIGHT, 100, 14*PER_HEIGHT) Font:14 Text:@"小萝莉" Color:FEELT_COLOR];
    [self.contentView addSubview:postionLb];
    
    contentLb=[MyControl createLabelWithFrame:CGRectMake(headerView.left, postionLb.bottom+15*PER_HEIGHT, SCREEN_WIDTH-24*PER_WIDTH, 14*PER_HEIGHT) Font:14 Text:@"这款新品很有个性,销量应该不错" Color:FEELT_COLOR];
   
    [self.contentView addSubview:contentLb];
    // 画虚线
    
    
    
    // 创建一个imageView 高度是你想要的虚线的高度 一般设为2
    _lineImg = [[UIImageView alloc] initWithFrame:CGRectMake(12*PER_WIDTH, contentLb.bottom+15*PER_HEIGHT, SCREEN_WIDTH-24*PER_WIDTH, 0.5)];
//    // 调用方法 返回的iamge就是虚线
//    _lineImg.image = [self drawLineByImageView:_lineImg];
//    // 添加到控制器的view上
   [self.contentView addSubview:_lineImg];
    [self drawDashLine:_lineImg lineLength:2 lineSpacing:1 lineColor:UIColorFromHex(0xcccccc)];
}



/**
 ** lineView:       需要绘制成虚线的view
 ** lineLength:     虚线的宽度
 ** lineSpacing:    虚线的间距
 ** lineColor:      虚线的颜色
 **/
- (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor
{
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setBounds:lineView.bounds];
    [shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
    [shapeLayer setFillColor:[UIColor clearColor].CGColor];
    //  设置虚线颜色为blackColor
    [shapeLayer setStrokeColor:lineColor.CGColor];
    //  设置虚线宽度
    [shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
    [shapeLayer setLineJoin:kCALineJoinRound];
    //  设置线宽，线间距
    [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
    //  设置路径
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL,CGRectGetWidth(lineView.frame), 0);
    [shapeLayer setPath:path];
    CGPathRelease(path);
    //  把绘制好的虚线添加上来
    [lineView.layer addSublayer:shapeLayer];
}
//- (UIImage *)drawLineByImageView:(UIImageView *)imageView{
//    UIGraphicsBeginImageContext(imageView.frame.size); //开始画线 划线的frame
//    [imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];
//    //设置线条终点形状
//    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
//    // 5是每个虚线的长度 1是高度
//    float lengths[] = {10, 20, 10};
//    CGContextRef line = UIGraphicsGetCurrentContext();
//    // 设置颜色
//    CGContextSetStrokeColorWithColor(line, [UIColor colorWithWhite:0.408 alpha:1.000].CGColor);
//    CGContextSetLineDash(line, 0, lengths, 2); //画虚线
//    CGContextMoveToPoint(line, 0.0, 2.0); //开始画线
//    CGContextAddLineToPoint(line, SCREEN_WIDTH - 10, 2.0);
//    
//    CGContextStrokePath(line);
//    // UIGraphicsGetImageFromCurrentImageContext()返回的就是image
//    return UIGraphicsGetImageFromCurrentImageContext();
//}
@end
